<table class="table table-hover table-bordered">
    <thead>
        <tr>
            <th colspan="12" style="font-size:20px;">表1-3-A 组织措施项目(整体)清单及计价表</th>
        </tr>
        <tr>
            <th>序号</th>
            <th>项目名称</th>
            <th>单位</th>
            <th>数量</th>
            <th>金额（元）</th>
            <th>至上期累计支付（元）</th>
            <th>本期上报金额</th>
            <th>监理审核</th>
            <th>备注</th>
        </tr>
    </thead>
    <tbody>
    <foreach name="results" item="vo">
        <tr name='{$vo.id}'>
            <td>{$vo.order_id}</td>
            <td>{$vo.item_name}</td>
            <td>{$vo.measurement_unit}</td>
            <td>{$vo.list_quantity}</td>
            <td>{$vo.list_amount}</td>
            <td>{$vo.last_month_accumulated_pay}</td>
            <td class="orgcomplete">{$vo.report_amount}</td>
            <td class="orgapproved">{$vo.approved_amount}</td>
            <td>{$vo.remark}</td>
        </tr>
    </foreach>
    </tbody>            
</table>
<script type="text/javascript">
$(document).ready(function(e) {
	<if condition="I('request.isAudit/s','') eq 2 AND I('request.level/s','') eq 3">
	var type = 2;
	// 监理经办人修改
	$(".orgapproved").click(function(){
		if($(this).find("input").val() == undefined){
			var value = $(this).html();
			$(this).html("<input type=\"text\" class='intval' style='width:"+$(this).width()+"px;' \>");
			$(".intval").focus();
			$(".intval").val(value);
		}
	});
	</if>
	<if condition="session('deptid') eq I('request.deptId/s', '') AND I('request.level/s','') eq 2">
	var type = 1;
	// 施工经办人修改
	$(".orgcomplete").click(function(){
		if($(this).find("input").val() == undefined){
			var value = $(this).html();
			$(this).html("<input type=\"text\" class='intval' style='width:"+$(this).width()+"px;' \>");
			$(".intval").focus();
			$(".intval").val(value);
		}
	});
	</if>
	// 失去光标 修改后台数据
	$(document).on("blur", ".intval", function(){
		$tr = $(this).closest("tr");
		var value = $(this).val() == '' ? 0.00 : $(this).val();
		// 修改后赋值
		$(this).closest("td").html(value);
		// 保存数据
		saveData($tr.attr("name"), value);
		// 计算总和
		getTotal();
	});
	
	// 请求地址 保存数据
	saveData = function(id, value){
		$.ajax({
			async	: false,
			url		: "{:U('PaymentReview/oml_post')}", 
			type	: "post", 
			dataType: "json", 
			data	: {'id': id, 'value': value, 'type': type}, 
			success : function(){
			},
			error	: function(){
				alert("服务器内部错误，请联系系统管理员");
			}
		});
	}
	
	// 计算总和
	getTotal = function(){
		var total = 0;
		var length = $("tbody > tr").length - 1;
		$("tbody > tr").each(function(i){
			if(i == length){
				return false;
			}
			<if condition="session('deptid') eq I('request.deptId/s', '') AND I('request.level/s','') eq 2">
				total += parseFloat($(this).find("td:eq(6)").html());
			</if>
			<if condition="I('request.isAudit/s','') eq 2 AND I('request.level/s','') eq 3">
				total += parseFloat($(this).find("td:eq(7)").html());
			</if>
		});
		var obj = $("tbody > tr:eq("+ length +")");
		<if condition="session('deptid') eq I('request.deptId/s', '') AND I('request.level/s','') eq 2">
			obj.find("td:eq(6)").html(total.toFixed(2));
		</if>
		<if condition="I('request.isAudit/s','') eq 2 AND I('request.level/s','') eq 3">
			obj.find("td:eq(7)").html(total.toFixed(2));
		</if>
		// 修改数据数据
		// saveData(obj.attr("name"), total);
	}
});
</script>